#include "Avalon/IOTests/NullClientConnection.hpp"

using namespace Avalon;
using namespace Avalon::IO;
using namespace Avalon::IO::Tests;
using namespace boost;
using namespace boost::signals2;

NullClientConnection::NullClientConnection()
    : m_isConnected(false) {}

NullClientConnection::~NullClientConnection() {
  Close();
}

void NullClientConnection::Connect() {
  boost::lock_guard<boost::mutex> lock(m_mutex);
  m_isConnected = true;
}

bool NullClientConnection::IsConnected() {
  boost::lock_guard<boost::mutex> lock(m_mutex);
  return m_isConnected;
}

void NullClientConnection::Close() {
  boost::lock_guard<boost::mutex> lock(m_mutex);
  if(!m_isConnected) {
    return;
  }
  m_isConnected = false;
  m_closedSignal();
}

connection NullClientConnection::ConnectClosedSignal(
    const ClosedSignal::slot_type& slot) {
  boost::lock_guard<boost::mutex> lock(m_mutex);
  return m_closedSignal.connect(slot);
}

connection NullClientConnection::ConnectClosedSignal(
    const ClosedSignal::slot_type& slot, bool* isConnected) {
  boost::lock_guard<boost::mutex> lock(m_mutex);
  *isConnected = m_isConnected;
  return m_closedSignal.connect(slot);
}
